package org.example.managere.repository.feibiao;

import org.example.managere.entity.feibiao.AmKnowledgeBasic;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface AmKnowledgeBasicRepository extends JpaRepository<AmKnowledgeBasic, String> {
    
    /**
     * 根据电机型号查询
     */
    List<AmKnowledgeBasic> findByMotorTypeContaining(String motorType);
    
    /**
     * 根据生产厂商查询
     */
    List<AmKnowledgeBasic> findByManufacturerContaining(String manufacturer);
    
    /**
     * 根据额定功率范围查询
     */
    List<AmKnowledgeBasic> findByRatedPowerBetween(BigDecimal minPower, BigDecimal maxPower);
    
    /**
     * 根据额定电压范围查询
     */
    List<AmKnowledgeBasic> findByRatedVoltageBetween(BigDecimal minVoltage, BigDecimal maxVoltage);
    
    /**
     * 根据关键字在电机ID、电机型号或厂商名称中进行模糊搜索
     */
    @Query("SELECT k FROM AmKnowledgeBasic k WHERE " +
           "k.motorId LIKE %:keyword% OR " +
           "k.motorType LIKE %:keyword% OR " +
           "k.manufacturer LIKE %:keyword%")
    Page<AmKnowledgeBasic> searchByKeyword(@Param("keyword") String keyword, Pageable pageable);
    
    /**
     * 根据电机型号精确查询
     */
    AmKnowledgeBasic findByMotorType(String motorType);
    
    /**
     * 统计某个生产厂商的电机数量
     */
    long countByManufacturer(String manufacturer);
} 